package io.rocketman.serialize.kryo.util;

import com.esotericsoftware.kryo.ClassResolver;
import com.esotericsoftware.kryo.Kryo;

/**
 * @author He Peng
 * @create 2018-05-26 16:31
 * @update 2018-05-26 16:31
 * @updatedesc : 更新说明
 * @see
 */
public class KryoUtils {

    private KryoUtils() {}

    public static boolean isRegistered(Kryo kryo , Class cls) {
        ClassResolver classResolver = kryo.getClassResolver();
        return classResolver.getRegistration(cls) != null ? true : false;
    }

    public static void maybeRegisterClass(Kryo kryo , Class cls) {
        if (! isRegistered(kryo , cls)) {
            kryo.register(cls);
        }
    }
}
